﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Web;


namespace onHaj.Code.BusinessLogic
{
    public class BL
    {
       

        public IEnumerable<ItineraryLeg> MakeItineraryLegs(HajCustomer haj)
        {
            var itineraries = new List<ItineraryLeg>();
            int i = 1;

   
            //Outbound processing
            if (string.IsNullOrEmpty(haj.OutboundSideAirport)) //no outbound side trip
            {
                var itinerary1 = new ItineraryLeg //direct from USA to JED
                                     {
                                         Sequence = i++,
                                         RequestedDepartureDate = Convert.ToDateTime(haj.USADepartureRequestedDate),
                                         DepartureAirport = haj.USADepartureAirport,
                                         ArrivalAirport = "JED",
                                     };
                itineraries.Add(itinerary1);
            }
            else //There is an outbound side trip
            {
                var itinerary2 = new ItineraryLeg //USA to Side, Side to JED
                                     {
                                         Sequence = i++,
                                         RequestedDepartureDate = Convert.ToDateTime(haj.USADepartureRequestedDate),
                                         DepartureAirport = haj.USADepartureAirport,
                                         RequestedArrivalDate = null,
                                         ArrivalAirport = haj.OutboundSideAirport
                                     };
                itineraries.Add(itinerary2);

                var itinerary3 = new ItineraryLeg
                                     {
                                         Sequence = i++,
                                         RequestedDepartureDate = null,
                                         DepartureAirport = haj.OutboundSideAirport,
                                         RequestedArrivalDate = new DateTime(2012,10,11),
                                         ArrivalAirport =  "JED"
                                     };
                itineraries.Add(itinerary3);
            }

            //Inbound processing
            if (string.IsNullOrEmpty(haj.InboundSideAirport)) //no inbound side trip
            {
                var itinerary4 = new ItineraryLeg //JED to USA
                                     {
                                         Sequence = i,
                                         RequestedDepartureDate = new DateTime(2012,10,30),
                                         DepartureAirport =  "JED",
                                         RequestedArrivalDate = null,
                                         ArrivalAirport = haj.USADepartureAirport
                                     };
                itineraries.Add(itinerary4);
            }
            else //There is an inbound side trip
            {
                var itinerary5 = new ItineraryLeg
                                     {
                                         Sequence = i++,
                                         RequestedDepartureDate = new DateTime(2012,10,30),
                                         DepartureAirport = "JED",
                                         RequestedArrivalDate = null,
                                         ArrivalAirport = haj.InboundSideAirport
                                     }; //JED side, side USA

                itineraries.Add(itinerary5);

                var itinerary6 = new ItineraryLeg
                                     {
                                         Sequence = i,
                                         RequestedDepartureDate = null,
                                         DepartureAirport = haj.InboundSideAirport,
                                         RequestedArrivalDate = Convert.ToDateTime(haj.InboundSideAirportDepartureDate),
                                         ArrivalAirport = haj.USADepartureAirport
                                     };
                itineraries.Add(itinerary6);
            }

            while (i < 4) //continue untill 4 if less than 4 itineraries has been added
            {
                var itineraryAdditional = new ItineraryLeg
                                              {
                                                  Sequence = ++i,
                                                  RequestedDepartureDate = null,
                                                  DepartureAirport = "",
                                                  RequestedArrivalDate = null,
                                                  ArrivalAirport = ""
                                              };
                itineraries.Add(itineraryAdditional);
            }

            return itineraries;
        }


    }
}